package org.apache.lucene.analysis.pinyin.solr6;

import java.util.Map;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.pinyin.lucene6.PinyinEdgeNGramTokenFilter;
import org.apache.lucene.analysis.util.TokenFilterFactory;

public class PinyinEdgeNGramTokenFilterFactory extends TokenFilterFactory {
    private int minGram;
    private int maxGram;
    private String side;
    private boolean nGramChinese;
    private boolean nGramNumber;

    public PinyinEdgeNGramTokenFilterFactory(Map<String, String> args) {
        super(args);

        this.minGram = getInt(args, "minGram", 2);
        this.maxGram = getInt(args, "maxGram", 10);
        this.side = get(args, "side", "front");
        this.nGramChinese = getBoolean(args, "nGramChinese", false);
        this.nGramNumber = getBoolean(args, "nGramNumber", false);
    }

    public TokenFilter create(TokenStream input) {
        return new PinyinEdgeNGramTokenFilter(input, this.side, this.minGram, this.maxGram,
            this.nGramChinese, this.nGramNumber);
    }
}